package ua.races.dom.docBuilder;

import org.jdom.Element;
import ua.races.vo.Race;

import java.util.List;
import java.util.ListIterator;

public class RaceDocumentBuilder extends DocumentBuilder {

    protected List<Race> races;

    public RaceDocumentBuilder(List<Race> races) {
        this.races = races;
    }

    public void build() {
        Race race = null;

        Element root = new Element("races");

        ListIterator<Race> iterator = races.listIterator();

        while (iterator.hasNext()) {
            Element raceElement = new Element("race");
            race = iterator.next();

            Element raceId = new Element("RaceId");
            raceId.setText(String.valueOf(race.getRaceId()));
            raceElement.addContent(raceId);

            Element raceDate = new Element("RaceDate");
            raceDate.setText(String.valueOf(race.getRaceDate()));
            raceElement.addContent(raceDate);

            Element startTime = new Element("StartTime");
            startTime.setText(String.valueOf(race.getStartTime()));
            raceElement.addContent(startTime);

            Element stadium = new Element("Stadium");
            stadium.setText(race.getStadium());
            raceElement.addContent(stadium);

            root.addContent(raceElement);
        }

        document.addContent(root);

    }

}